package 恰好型滑动窗口

func countOfSubstrings(word string, k int) int64 {
	diff1 := map[byte]int{}
	diff2 := map[byte]int{}
	s1, s2, left1, left2, cnt1, cnt2 := 0, 0, 0, 0, 0, 0
	for right, c := range word {
		if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' {
			diff1[byte(c)]++
			diff2[byte(c)]++
		} else {
			s1++
			s2++
		}
		for s1 >= k && len(diff1) >= 5 && left1 <= right {
			d := word[left1]
			if d == 'a' || d == 'e' || d == 'i' || d == 'o' || d == 'u' {
				diff1[byte(d)]--
				if diff1[byte(d)] == 0 {
					delete(diff1, d)
				}
			} else {
				s1--
			}
			left1++
		}
		cnt1 += left1
		for s2 >= k+1 && len(diff2) >= 5 && left2 <= right {
			d := word[left2]
			if d == 'a' || d == 'e' || d == 'i' || d == 'o' || d == 'u' {
				diff2[byte(d)]--
				if diff2[byte(d)] == 0 {
					delete(diff2, d)
				}
			} else {
				s2--
			}
			left2++
		}
		cnt2 += left2
	}
	return int64(cnt1 - cnt2)
}
